package com.kehutong.contact.entity;

import com.kehutong.contact.enums.CustomerSource;
import com.kehutong.contact.enums.CustomerStatus;
import com.kehutong.contact.enums.CustomerType;
import com.kehutong.contact.enums.RoleType;
import com.kehutong.contact.util.DateUtil;
import org.coraframework.bean.valid.CheckField;
import org.coraframework.orm.Entity;
import org.coraframework.orm.annotation.Column;
import org.coraframework.orm.annotation.Table;
import org.coraframework.orm.annotation.UnSave;
import org.coraframework.orm.util.IDType;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.UUID;

/**
 * 客户管理
 * @author liujinwang
 */
@Table(value="t_customer",comment="客户表", multi=true, idType= IDType.TIMESTAMP)
public class Customer extends Entity {
    private static final long serialVersionUID = -4497526184578322942L;

    protected Customer(String id) {
        super(id);
    }
    // ----------------基础信息----------------

    @CheckField("客户名称不能为空")
    @Column(comment="客户名称", length = 25)
    private String corpFullName;

    @Column(comment="系统编号")
    private String systemNo;

    @Column(comment="简称")
    private String corpName;

    @CheckField("所属行业不能为空")
    @Column(comment="所属行业")
    private String industry;

    @CheckField("客户类型不能为空")
    @Column(comment="客户类型")
    private CustomerType customerType;

    @CheckField("客户状态不能为空")
    @Column(comment="客户状态")
    private CustomerStatus customerStatus;

    @CheckField("客户星级不能为空")
    @Column(comment="客户星级")
    private String customerStar;

    @Column(comment="客户来源")
    private CustomerSource customerSource;

    @CheckField("客户归属不能为空")
    @Column(comment="客户归属")
    private String customerBelong;

    @Column(comment="归属id")
    private String customerBelongId;

    // ----------------附加信息----------------
    @Column(comment="所在地区")
    private String location;

    @Column(comment="详细地址")
    private String address;

    @Column(comment = "企业规模")
    private String scale;

    @Column(comment = "备注",length = 300)
    private String remark;
    //-----------------首联系人-----------------

    @CheckField("联系人姓名不能为空")
    @Column(comment = "联系人姓名")
    private String contactName;

    @Column(comment = "联系人id")
    private String contactId;

    @Column(comment = "尊称 1先生，2女士",defValue = "NOT NULL default '0'")
    private String sirOrLady;

    @Column(comment = "角色")
    private RoleType role;

    @Column(comment = "生日")
    private LocalDate birthday;

    @Column(comment = "职位")
    private String position;

    @CheckField("联系人姓名不能为空")
    @Column(comment = "手机号码")
    private String mobile;

    @Column(comment = "电子邮箱")
    private String email;

    @Column(comment = "固定电话")
    private String telephone;

    @Column(comment = "传真号码")
    private String fax;

    @Column(comment = "微信账号")
    private String wechat;

    @Column(comment = "QQ号码")
    private String qq;

    @Column(comment = "所在地区")
    private String areaName;

    @Column(comment = "详细地址")
    private String detailAddress;

    @Column(comment = "备注信息",length = 300)
    private String remarkMsg;

    @Column(comment="首要联系人")
    private boolean firstContact;
    //-----------------系统信息-----------------
    @Column(comment = "所属企业")
    private String enterpriseBelong;

    @Column(comment = "关联用户")
    private String relatedUser;

    @Column(comment = "创建人员")
    private String createBy;

    @Column(comment = "跟进人员")
    private String followUpName;

    @Column(comment = "跟进人员id")
    private String followUpId;

    @Column(comment="重点关注")
    private boolean focus;

    @Column(comment = "最后跟进时间")
    private LocalDateTime lastFollowUpTime;

    /**
     * 未跟进天数
     */
    @UnSave
    private int noContactDays;

    @Column(comment="逻辑删除")
    private boolean deleted;

    public String getCorpFullName() {
        return corpFullName;
    }

    public void setCorpFullName(String corpFullName) {
        this.corpFullName = corpFullName;
    }

    public String getSystemNo() {
        if (Objects.isNull(systemNo)) {
            systemNo = UUID.randomUUID().toString();
        }
        return systemNo;
    }

    public void setSystemNo(String systemNo) {
        this.systemNo = systemNo;
    }

    public String getCorpName() {
        return corpName;
    }

    public void setCorpName(String corpName) {
        this.corpName = corpName;
    }

    public String getIndustry() {
        return industry;
    }

    public void setIndustry(String industry) {
        this.industry = industry;
    }

    public CustomerType getCustomerType() {
        return customerType;
    }

    public void setCustomerType(CustomerType customerType) {
        this.customerType = customerType;
    }

    public CustomerStatus getCustomerStatus() {
        return customerStatus;
    }

    public void setCustomerStatus(CustomerStatus customerStatus) {
        this.customerStatus = customerStatus;
    }

    public String getCustomerStar() {
        return customerStar;
    }

    public void setCustomerStar(String customerStar) {
        this.customerStar = customerStar;
    }

    public CustomerSource getCustomerSource() {
        return customerSource;
    }

    public void setCustomerSource(CustomerSource customerSource) {
        this.customerSource = customerSource;
    }

    public String getCustomerBelong() {
        return customerBelong;
    }

    public void setCustomerBelong(String customerBelong) {
        this.customerBelong = customerBelong;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCustomerBelongId() {
        return customerBelongId;
    }

    public void setCustomerBelongId(String customerBelongId) {
        this.customerBelongId = customerBelongId;
    }

    public String getContactId() {
        return contactId;
    }

    public void setContactId(String contactId) {
        this.contactId = contactId;
    }

    public String getFollowUpId() {
        return followUpId;
    }

    public void setFollowUpId(String followUpId) {
        this.followUpId = followUpId;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getScale() {
        return scale;
    }

    public void setScale(String scale) {
        this.scale = scale;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getSirOrLady() {
        return sirOrLady;
    }

    public void setSirOrLady(String sirOrLady) {
        this.sirOrLady = sirOrLady;
    }

    public RoleType getRole() {
        return role;
    }

    public void setRole(RoleType role) {
        this.role = role;
    }

    public LocalDate getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDate birthday) {
        this.birthday = birthday;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getWechat() {
        return wechat;
    }

    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public String getDetailAddress() {
        return detailAddress;
    }

    public void setDetailAddress(String detailAddress) {
        this.detailAddress = detailAddress;
    }

    public String getRemarkMsg() {
        return remarkMsg;
    }

    public void setRemarkMsg(String remarkMsg) {
        this.remarkMsg = remarkMsg;
    }

    public boolean isFirstContact() {
        return firstContact;
    }

    public void setFirstContact(boolean firstContact) {
        this.firstContact = firstContact;
    }

    public String getEnterpriseBelong() {
        return enterpriseBelong;
    }

    public void setEnterpriseBelong(String enterpriseBelong) {
        this.enterpriseBelong = enterpriseBelong;
    }

    public String getRelatedUser() {
        return relatedUser;
    }

    public void setRelatedUser(String relatedUser) {
        this.relatedUser = relatedUser;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public String getFollowUpName() {
        return followUpName;
    }

    public void setFollowUpName(String followUpName) {
        this.followUpName = followUpName;
    }

    public boolean isFocus() {
        return focus;
    }

    public void setFocus(boolean focus) {
        this.focus = focus;
    }

    public LocalDateTime getLastFollowUpTime() {
        if (Objects.isNull(lastFollowUpTime)) {
            lastFollowUpTime = LocalDateTime.now();
        }
        return lastFollowUpTime;
    }

    public void setLastFollowUpTime(LocalDateTime lastFollowUpTime) {
        this.lastFollowUpTime = lastFollowUpTime;
    }

    public int getNoContactDays() {
        String startTime = lastFollowUpTime.format(DateTimeFormatter.ofPattern(DateUtil.YEAR_MONTH_DAY));
        String endTime = DateUtil.getTime(DateUtil.YEAR_MONTH_DAY);
        return DateUtil.getDateSpace(startTime, endTime);
    }

    public void setNoContactDays(int noContactDays) {
        this.noContactDays = noContactDays;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }
}
